<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<script type="text/javascript" src="${initParam.root }smarteditor/js/HuskyEZCreator.js" charset="utf-8"></script>
<script type="text/javascript">
	$(function(){
		 
		var str=$("#content").val();
		var count=0;
		for(var i=0;i<str.length;i++){
			count++;
		}
		$("#letterCount").html(count); 
		
		$("#cancel").click(function(){
			if(confirm("수정을 취소하시겠습니까?")){
				location.href="${initParam.root}collection/auth_detailCollectionNoHit.do?no=${requestScope.detailInfo.bvo.no}";
			}
		});
		
		$("#submitForm").click(function(){
			if($("#content").val()==""){
				alert("내용을 입력하세요");
				return false;
			}
			if($("#title").val()==""){
				alert("제목을 입력하세요");
				return false;
			}
		});

		
		$("#fileView").hide();
		
		/* $("#fileDelete").click(function(){
			if(confirm("삭제하시겠습니까?")){
				//$(".fileName"+index+"").hide();
				var index=$("#fileList div").attr("class"); //인덱스 가져오기
				$(this).hide();
				return $(".fileView"+index+"").html("<input type=file name=files["+index+"] >");
			}
		}); */
		
		for(var i=0;i<=2;i++){
			//alert($(".fileView"+i+"").text());
			$(".fileView"+i).hide();
		}
		
			
	});//ready
		
	function filePlus(){
		$("#filePlus").hide();
		$("#fileView").show();
	}
	function deleteFile(index,newFileName){
		//alert(index +" "+newFileName);
		if(confirm("삭제하시겠습니까?")){
			$("#deleteFile"+index+"").hide();
			//$("#newFileList").show();
			$(".fileView"+index+"").show();
		}
	}
	
</script>
</head>
<body>
<form action="${initParam.root }collection/auth_updateCollectionGo.do" method="post"  enctype="multipart/form-data" id="updateF" >
<input type="hidden" name="no" value="${requestScope.detailInfo.bvo.no}">
<table width="550">
		<tr>
			<td align="right">Title</td>
			<td><input size="65" type="text" name="title" id="title" value="${requestScope.detailInfo.bvo.title }"></td>
		</tr>
		<tr>
			<td align="right" valign="top">
				Content
			</td>
			<td>
				<textarea rows="15" cols="57" name="content" id="content" style="resize: none;">${requestScope.detailInfo.bvo.content }</textarea>
			</td>
		</tr>
		<tr>
			<td colspan="3" align="right"><span id="letterCount"></span>/3000자</td>
		</tr>
		<tr>
			<td rowspan="3" align="right" valign="top">File<br>Attachment</td>
			<td>
				<c:choose>
				<c:when test='${fn:length(requestScope.detailInfo.fileList)!=0 }'>
					<div id="fileList">
					<c:forEach var="list" items="${requestScope.detailInfo.fileList }" varStatus="count">
						<%-- <div class="${count.index }" id="fileDelete">
							${list.newFileName }
						</div> --%>
						<%-- <input type="file" name="files[${count.index }]" id="files${count.index }"> --%>
						<a href="#" onclick="deleteFile('${count.index}','${list.newFileName }')" id="deleteFile${count.index }">${list.orgFileName }</a>
						<span class="fileView${count.index }" ><input type="file" name="files[${count.index }]"></span><br>
					</c:forEach>
					</div>
				</c:when>
				<c:otherwise>
					<span id="filePlus"><input type="button" name="fileView" value="파일추가" onclick="filePlus()"></span>
					<span id="fileView"><input type="file" name="files[0] "><br>
					<input type="file" name="files[1]" ><br>
					<input type="file" name="files[2]" ></span>
				</c:otherwise>
				</c:choose>
			</td>
		</tr>
		<tr>
			<td colspan="2" align="right" style="padding-right: 25px;">
				<input type="button" name="cancel" id="cancel" value="취소">
				<input type="submit" value="수정" id="submitForm">
			</td>
		</tr>
	</table>
</form>	
